#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
class Solution
{
public:
    vector<int> numberOfLines(vector<int> &widths, string s)
    {
        int ans = 0, line = 1;
        for (int i = 0; i < s.length(); i++)
        {
            ans += widths[s[i] - 'a'];

            if (ans + widths[s[i]] > 100)
            {
                line++;
                ans = 0;
                i -= 1;
            }
            if (ans == 100)
            {
                line++;
                ans = 0;
            }
        }
        // cout << ans << endl;
        return {line, ans};
    }

    vector<int> numberOfLines_2(vector<int> &widths, string s)
    {
        const int MAX_WIDTH = 100;
        int lines = 1, width = 0;
        for (auto &c : s)
        {
            int need = widths[c - 'a'];
            width += need;
            if (width > MAX_WIDTH)
            {
                lines++;
                // nice, init next
                width = need;
            }
        }
        return {lines, width};
    }
};
int main()
{
    Solution s;
    vector<int> widths = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
                          10, 10, 10, 10, 10, 10, 10};
    string S = "abcdefghijklmnopqrstuvwxyz";
    vector<int> ans = s.numberOfLines(widths, S);
    cout << ans[0] << " " << ans[1] << endl;
    system("pause");
    return 0;
}
